//
//  EVBaseView.m
//  EVClub
//
//  Created by LiJieming on 15/5/22.
//  Copyright (c) 2015年 BitRice. All rights reserved.
//

#import "EVBaseView.h"
#import "NSArray+EV.h"

@implementation EVBaseView
@synthesize contentView = _contentView;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpBaseView];
    }
    return self;
}

- (id)initWithCoder:(NSCoder*)coder {
    if (self = [super initWithCoder:coder]) {
        [self setUpBaseView];
    }
    return self;
}

- (void)setUpBaseView {
//#ifdef DEBUG
//    BOOL showInIB = [UIApplication sharedApplication] == nil;
//    if (showInIB) {
//        return;
//    }
//#endif
    if (self.viewInitNib != nil) {
        NSArray *array = [self.viewInitNib instantiateWithOwner:self options:nil];
        _contentView = [array ev_objectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
            return [obj isKindOfClass:[UIView class]];
        }];
        _contentView.frame = self.bounds;
        _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [self addSubview:_contentView];
    }
}

- (UINib *)viewInitNib {
    if ([[NSBundle mainBundle] pathForResource:NSStringFromClass([self class]) ofType:@"nib"] != nil) {
        return [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil];
    }
    return nil;
}

//#ifdef DEBUG
//- (void)drawRect:(CGRect)rect {
//    BOOL showInIB = [UIApplication sharedApplication] == nil;
//    if (showInIB) {
//        NSString *className = NSStringFromClass(self.class);
//        CGRect classNameRect = [className boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0], NSForegroundColorAttributeName:[UIColor normalTextColor]} context:nil];
//        CGPoint origin = CGPointMake(rect.size.width / 2 - classNameRect.size.width / 2,
//                                     rect.size.height / 2 - classNameRect.size.height / 2);
//        [className drawAtPoint:origin withAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15.0], NSForegroundColorAttributeName: [UIColor normalTextColor]}];
//    }
//}
//#endif

@end
